{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "answers_path = \"answers.json\"\n",
    "train_path = \"train.json\"\n",
    "test_path = \"test.json\"\n",
    "valid_path = \"valid.json\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(answers_path) as f:\n",
    "    answers = json.load(f)\n",
    "    \n",
    "with open(train_path) as f:\n",
    "    trains = json.load(f)\n",
    "    \n",
    "with open(test_path) as f:\n",
    "    test = json.load(f)\n",
    "    \n",
    "with open(train_path) as f:\n",
    "    valid = json.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "docs = []\n",
    "for k, item in answers.items():\n",
    "    docs.append(item[\"zh\"].strip())\n",
    "\n",
    "for k, item in trains.items():\n",
    "    docs.append(item[\"zh\"].strip())\n",
    "\n",
    "for k, item in test.items():\n",
    "    docs.append(item[\"zh\"].strip())\n",
    "\n",
    "for k, item in valid.items():\n",
    "    docs.append(item[\"zh\"].strip())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import jieba\n",
    "import re"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Building prefix dict from the default dictionary ...\n",
      "Dumping model to file cache /tmp/jieba.cache\n",
      "Loading model cost 2.138 seconds.\n",
      "Prefix dict has been built succesfully.\n"
     ]
    }
   ],
   "source": [
    "docs_ = [jieba.lcut(s) for s in docs]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['许多',\n",
       " '公司',\n",
       " '提供',\n",
       " '混合',\n",
       " '年金',\n",
       " '或',\n",
       " '年',\n",
       " '金',\n",
       " '与',\n",
       " '发病率',\n",
       " '车手',\n",
       " '，',\n",
       " '如',\n",
       " '长期',\n",
       " '护理',\n",
       " '，',\n",
       " '严重',\n",
       " '疾病',\n",
       " '，',\n",
       " '灾难性',\n",
       " '疾病',\n",
       " '，',\n",
       " '终末期',\n",
       " '疾病',\n",
       " '等',\n",
       " '。',\n",
       " '但是',\n",
       " '，',\n",
       " '一个',\n",
       " '美国',\n",
       " '领先',\n",
       " '的',\n",
       " '年',\n",
       " '金',\n",
       " '分销商',\n",
       " '之一',\n",
       " '，',\n",
       " '长期',\n",
       " '照顾',\n",
       " '骑手',\n",
       " '固定',\n",
       " '利率',\n",
       " '受欢迎',\n",
       " '年金',\n",
       " '从',\n",
       " '其他',\n",
       " '年',\n",
       " '金',\n",
       " '接受',\n",
       " '1035',\n",
       " '次',\n",
       " '交易',\n",
       " '。']"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "docs_[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gensim.models import Word2Vec"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'sentences' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-6-bca5d8abf437>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmodel\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mWord2Vec\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msentences\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msg\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m,\u001b[0m  \u001b[0mwindow\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m,\u001b[0m  \u001b[0mmin_count\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m,\u001b[0m  \u001b[0mnegative\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msample\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0.001\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mworkers\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m: name 'sentences' is not defined"
     ]
    }
   ],
   "source": [
    "model = Word2Vec(sentences, sg=1, size=100,  window=5,  min_count=5,  negative=3, sample=0.001, hs=1, workers=4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
